package com.wngbms.netty.seatdemo.comm;

public enum BodyType {

    NON((byte) 0b000, (byte) 3, "无消息体"),
    TEXT((byte) 0b001, (byte) 3, "普通文本UTF-8编码"),
    JSON((byte) 0b010, (byte) 3, "JSON文本UTF-8编码"),
    XML((byte) 0b011, (byte) 3, "XML文本UTF-8编码"),
    PROTOBUF((byte) 0b100, (byte) 3, "protobuf"),
    BINARY((byte) 0b101, (byte) 3, "二进制流"),

    ;
    byte type;
    byte bitLen; // 占用的比特位数
    String desc;

    BodyType(byte type, byte bitLen, String desc) {
        this.type = type;
        this.bitLen = bitLen;
        this.desc = desc;
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static BodyType find(byte val) {
        BodyType[] values = BodyType.values();
        for (int i = 0; i < values.length; i++) {
            if (values[i].getType() == val) {
                return values[i];
            }
        }
        return null;
    }
}
